﻿using System.Data;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Mota.XMLControls
{
    /// <summary>
    /// Represent Numeric control based on DX TrackBarControl 
    /// </summary>
    public class DXGuiTrackBar:GuiTrackBar
    {
        /// <summary>
        /// Create TrackBarControl control
        /// </summary>
        public DXGuiTrackBar()
        {

            visualControl = new TrackBarControl();
            (visualControl as TrackBarControl).ShowToolTips = true;
            (visualControl as TrackBarControl).Properties.ShowValueToolTip = true;
            (visualControl as TrackBarControl).ValueChanged += DXGuiTrackBar_ValueChanged;
        }

        void DXGuiTrackBar_ValueChanged(object sender, System.EventArgs e)
        {
            this.ChangeEventCall(null);
        }
        /// <summary>
        /// GET|SET TrackBarControl Text property
        /// </summary>
        public override string Text
        {
            get
            {
                return (visualControl as TrackBarControl).Text;
            }
            set
            {
                (visualControl as TrackBarControl).Text = value;
            }
        }

        /// <summary>
        /// GET|SET TrackBarControl.Properties.TickFrequency  property
        /// </summary>

        public override int Step
        {
            get
            {
                return (visualControl as TrackBarControl).Properties.TickFrequency;
            }
            set
            {
                (visualControl as TrackBarControl).Properties.TickFrequency = value;
            }
        }

        /// <summary>
        /// GET|SET TrackBarControl.Properties.Minimum property
        /// </summary>

        public override int Min
        {
            get
            {
                return (visualControl as TrackBarControl).Properties.Minimum;
            }
            set
            {
                (visualControl as TrackBarControl).Properties.Minimum = value;
            }
        }
        /// <summary>
        /// GET|SET TrackBarControl.Properties.Maximum property
        /// </summary>
        public override int Max
        {
            get
            {
                return (visualControl as TrackBarControl).Properties.Maximum;
            }
            set
            {
                (visualControl as TrackBarControl).Properties.Maximum = value;
            }
        }
        /// <summary>
        /// Add DataBinding to TrackBarControl Value property
        /// </summary>
        /// <param name="valueBinding">main binding source with current record values</param>
        public override void SetValue(object valueBinding)
        {
            if(valueBinding is BindingSource)
                (visualControl as TrackBarControl).DataBindings.Add("Value", valueBinding as BindingSource, XmlAttributes["XMLAttribute"], true);

        }
        /// <summary>
        /// Dummy property
        /// </summary>
        public override object Binding
        {
            get
            {
                return null;
            }
            set
            {
               // throw new System.NotImplementedException();
            }
        }

        public override object GetValue()
        {
            return (visualControl as TrackBarControl).Value;
        }
    }
}
